﻿/*
 * @author: wizardc
 */

using System.IO;
using zlib;

namespace Dou.Utils
{
    /// <summary>
    /// ZLib 压缩解压工具类
    /// </summary>
    public static class ZLibUtil
    {
        /// <summary>
        /// 压缩
        /// </summary>
        public static byte[] Compress(byte[] bytes)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                using (ZOutputStream zOut = new ZOutputStream(ms))
                {
                    zOut.Write(bytes, 0, bytes.Length);
                    zOut.finish();
                    return ms.ToArray();
                }
            }
        }

        /// <summary>
        /// 解压
        /// </summary>
        public static byte[] Decompress(byte[] bytes)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                using (ZOutputStream zOut = new ZOutputStream(ms))
                {
                    zOut.Write(bytes, 0, bytes.Length);
                    zOut.finish();
                    return ms.ToArray();
                }
            }
        }
    }
}
